# File: ConfigureViewports.py
#
# Author: Jalmar Teeuw
# Date: 16 December 2008
#

# import libraries
import wx


#####
# Class Definition
#####

class ConfigureViewports(wx.Dialog):
	
	#####
	# Constructor
	#####
	
	# constructor
	# ------
	def __init__(self, parent, id = -1):
		'''
			Create a new viewports configuration dialog.
			
			@param parent: the parent to the dialog
			@param id: the id of the dialog (defaults to -1)
		'''
		
		# call super constructor
		wx.Dialog.__init__(self, parent, id)
		
		# store reference to vtkcomp
		self._vtkcomp = parent.FindWindowById(parent.VISUALIZER)
		
		# construct main panel
		mpanel = wx.Panel(self, id)
		msizer = wx.BoxSizer(wx.VERTICAL)
		mpanel.SetSizer(msizer)
		
		# add single viewport configuration panel to sizer
		msizer.Add(self._initSingleViewportPanel(self._vtkcomp.GetSingleViewportOptions(), mpanel), 0, wx.EXPAND | wx.ALL, 10)
		
		# add multiple viewport configuration panel to sizer
		msizer.Add(self._initMultiViewportPanel(self._vtkcomp.GetMultipleViewportsOptions(), mpanel), 0, wx.EXPAND | wx.ALL, 10)
		
		# add render quality configuration panel to sizer
		msizer.Add(self._initRenderQualityPanel(self._vtkcomp.GetRenderQualityOptions(), mpanel), 0, wx.EXPAND | wx.ALL, 10)
		
		# add stretch spacer to panel sizer (keeps buttons at bottom)
		msizer.AddStretchSpacer()
		
		# add buttons panel
		msizer.Add(self._initButtonsPanel(mpanel), 0, wx.EXPAND | wx.ALL, 10)
		
		# size dialog
		self.SetSize(size = (300, 420))
		self.CenterOnScreen()
		
	
	#####
	# Panel Consutruction Procedures
	#####
	
	# single viewport configuration panel
	def _initSingleViewportPanel(self, defaults, parent, id = -1):
		'''
			Construct the configuration panel for the single viewport screen
			
			@param defaults: a list with the default options selected
			@param parent: the parent to the configuration panel
			@param id: the id of the configuration panel (defaults to -1)
		'''
		
		# create static box
		sbox = wx.StaticBox(parent, id, "Single Viewport Configuration Options:")
		
		# create sizer
		sizer = wx.StaticBoxSizer(sbox, wx.VERTICAL)
		
		# add view type selection
		hsizer = wx.GridSizer(1, 2)
		label = wx.StaticText(parent, id, "Viewport:")
		self.svcbox = wx.Choice(parent, id, choices = ["3D View (P)", "3D View (O)", "Left View", "Right View", "Top View", "Bottom View", "Front View", "Back View"])
		self.svcbox.SetSelection(defaults[0])
		
		hsizer.Add(label)
		hsizer.Add(self.svcbox)
		sizer.Add(hsizer)
		
		# return sizer
		return sizer
	
	
	# single viewport configuration panel
	def _initMultiViewportPanel(self, defaults, parent, id = -1):
		'''
			Construct the configuration panel for the multiple viewports screen
			
			@param defaults: a list with the default options selected
			@param parent: the parent to the configuration panel
			@param id: the id of the configuration panel (defaults to -1)
		'''
		
		# create static box
		sbox = wx.StaticBox(parent, id, "Multiple Viewports Configuration Options:")
		
		# create sizer
		sizer = wx.StaticBoxSizer(sbox, wx.VERTICAL)
		
		# add view type selection
		gsizer = wx.GridSizer(4, 2)
		
		tllabel = wx.StaticText(parent, id, "Top Left:")
		self.tlmvcbox = wx.Choice(parent, id, choices = ["3D View (P)", "3D View (O)", "Left View", "Right View", "Top View", "Bottom View", "Front View", "Back View"])
		self.tlmvcbox.SetSelection(defaults[0])
		
		trlabel = wx.StaticText(parent, id, "Top Right:")
		self.trmvcbox = wx.Choice(parent, id, choices = ["3D View (P)", "3D View (O)", "Left View", "Right View", "Top View", "Bottom View", "Front View", "Back View"])
		self.trmvcbox.SetSelection(defaults[1])
		
		bllabel = wx.StaticText(parent, id, "Bottom Left:")
		self.blmvcbox = wx.Choice(parent, id, choices = ["3D View (P)", "3D View (O)", "Left View", "Right View", "Top View", "Bottom View", "Front View", "Back View"])
		self.blmvcbox.SetSelection(defaults[2])
		
		brlabel = wx.StaticText(parent, id, "Bottom Right:")
		self.brmvcbox = wx.Choice(parent, id, choices = ["3D View (P)", "3D View (O)", "Left View", "Right View", "Top View", "Bottom View", "Front View", "Back View"])
		self.brmvcbox.SetSelection(defaults[3])
		
		gsizer.Add(tllabel)
		gsizer.Add(self.tlmvcbox)
		gsizer.Add(trlabel)
		gsizer.Add(self.trmvcbox)
		gsizer.Add(bllabel)
		gsizer.Add(self.blmvcbox)
		gsizer.Add(brlabel)
		gsizer.Add(self.brmvcbox)
		
		sizer.Add(gsizer)
		
		# return sizer
		return sizer


	# render quality configuration
	def _initRenderQualityPanel(self, defaults, parent, id = -1):
		'''
			Construct the configuration panel for the render quality
			
			@param defaults: a list with the default options selected
			@param parent: the parent to the configuration panel
			@param id: the id of the configuration panel (defaults to -1)
		'''
		
		# create static box
		sbox = wx.StaticBox(parent, id, "Render Quality Configuration Options:")
		
		# create sizer
		sizer = wx.StaticBoxSizer(sbox, wx.VERTICAL)
		
		# add view type selection
		gsizer = wx.GridSizer(2, 2)
		
		#dblabel = wx.StaticText(parent, id, "Double Buffering:")
		self.dbcb = wx.CheckBox(parent, id, "Double Buffering")
		self.dbcb.SetValue(defaults[0])
		
		#dplabel = wx.StaticText(parent, id, "Depth Peeling:")
		self.dpcb = wx.CheckBox(parent, id, "Depth Peeling")
		self.dpcb.SetValue(defaults[1])
		
		#aalabel = wx.StaticText(parent, id, "Anti-aliasing:")
		self.aacb = wx.CheckBox(parent, id, "Anti-aliasing")
		self.aacb.SetValue(defaults[2])
		
		#gsizer.Add(dblabel)
		#gsizer.Add(self.dbcb)
		#gsizer.Add(dplabel)
		#gsizer.Add(self.dpcb)
		#gsizer.Add(aalabel)
		#gsizer.Add(self.aacb)
		
		#sizer.Add(gsizer)
		
		sizer.Add(self.dbcb)
		sizer.Add(self.dpcb)
		sizer.Add(self.aacb)
		
		# return sizer
		return sizer
	
	
	# buttons panel
	def _initButtonsPanel(self, parent, id = -1):
		'''
			Construct the panel with the Cancel and Apply buttons
			
			@param parent: the parent to the panel
			@param id: the id of the panel (defaults to -1)
		'''
		
		# create panel
		panel = wx.Panel(parent, id)
		
		# create sizer
		sizer = wx.BoxSizer(wx.HORIZONTAL)
		
		# create buttons
		cancelButton = wx.Button(panel, 837, "Cancel")
		applyButton = wx.Button(panel, 838, "Apply")
		
		# add buttons
		sizer.AddStretchSpacer()
		sizer.Add(cancelButton, 0, wx.ALIGN_RIGHT | wx.ALL, 10)
		sizer.Add(applyButton, 0, wx.ALIGN_RIGHT | wx.ALL, 10)
		
		# set sizer
		panel.SetSizer(sizer)
		
		# bind events
		cancelButton.Bind(wx.EVT_BUTTON, self._btnCancel)
		applyButton.Bind(wx.EVT_BUTTON, self._btnApply)
		
		# return panel
		return panel


	#####
	# Window Events
	#####

	# cancel button
	def _btnCancel(self, event):
		'''
			Private button event.
			
			@param event: button event
		'''
		
		# end modal dialog
		self.EndModal(wx.ID_CANCEL)
		
	
	# apply button
	def _btnApply(self, event):
		'''
			Private button event.
			Apply new settings to the VTK Component
			
			@param event: button event
		'''
		
		# set single viewport options
		self._vtkcomp.SetSingleViewportOptions([ self.svcbox.GetSelection() ])
		
		# set multiple viewports options
		self._vtkcomp.SetMultipleViewportsOptions([ self.tlmvcbox.GetSelection(), self.trmvcbox.GetSelection(), self.blmvcbox.GetSelection(), self.brmvcbox.GetSelection() ])
		
		# set render quality options
		self._vtkcomp.SetRenderQualityOptions([ self.dbcb.IsChecked(), self.dpcb.IsChecked(), self.aacb.IsChecked() ])
		
		# end modal dialog
		self.EndModal(wx.ID_APPLY)
	
